<?php
class ui_recommend_default extends ui {
	public function __construct($S, $param) {
		parent::__construct();
		
		if ($this->uid) {
			// Nav
			$S->assign('nav', loadMod('glob/nav/0'));
			
			// 列出全部给我发送过推荐的好友
			$data_friend = new data_friend();
			$friends = $data_friend->ls($this->uid, 'receive', 'all', 1, 0);
			if (is_array($friends)) {
				$current_friend_id = 0;
				foreach ($friends as $k=>$v) {
					if ($v['friend_id'] == intval($_GET['fid'])) {
						$friends[$k]['is_current'] = true;
						$current_friend_id = $v['friend_id'];
					}
				}
			}
			$S->assign('friends', $friends);
			$S->assign('current_friend_id', $current_friend_id);

			// 参数
			$_GET['page']	= ($_GET['page']>1) ? intval($_GET['page']) : 1;
			$limit 		= 10;
			
			$data_recommend_article = new data_recommend_article();
			$articles = $data_recommend_article->ls($this->uid, 'all', $current_friend_id, $_GET['page'], $limit);
				
			// 判断第一页和最后一页
			$is_last = 0;
			if ($_GET['page'] > 1 and empty($articles)) {					// 不是第一页，而且没有数据了，那么一定就是最后一页了
				$is_last = 1;
				$_GET['page'] = $_GET['page'] - 1;
				$articles = $data_recommend_article->ls($this->uid, 'all', $current_friend_id, $_GET['page'], $limit);
			}
			$S->assign('articles', 	$articles);
			$S->assign('is_last', 	$is_last);
			$S->assign('page', 	$_GET['page']);
		} else {
			die2page('http://uread.me');
		}
	}
}
?>